<!DOCTYPE html>
<html>

<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="../js/bootstrap/css/bootstrap.min.css">
    <script src="../js/jquery/jquery.min.js"></script>
    <script src="../js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/myStrategyComment.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="../js/plugins/jquery-form/jquery.form.js"></script>
    <link rel="stylesheet" href="../js/plugins/dialog2/dialog.css">
    <script src="../js/plugins/dialog2/dialog.min.js"></script>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:window.history.go(-1)">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>

        </div>
        <div class="col">
            <span>点评</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<div class="comment">
    <div class="container star">
        <p>你对该旅游地的评价</p>
        <i class="fa fa-star-o fa-lg starNum" data-num="1"></i>
        <i class="fa fa-star-o fa-lg starNum" data-num="2"></i>
        <i class="fa fa-star-o fa-lg starNum" data-num="3"></i>
        <i class="fa fa-star-o fa-lg starNum" data-num="4"></i>
        <i class="fa fa-star-o fa-lg starNum" data-num="5"></i>
    </div>
    <hr/>
    <div class="container tag">
        <p>请为该旅游地选择合适的标签（大家都在评）</p>
        <div class="btn-group-toggle" data-toggle="buttons">
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="价格便宜"> 价格便宜
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="住宿方便"> 住宿方便
            </label>
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="旅游景点多"> 旅游景点多
            </label>
            <label class="btn btn-outline-danger ">
                <input type="checkbox" autocomplete="off" value="适合拍照">适合拍照
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="吃的很多">吃的很多
            </label>
            <label class="btn btn-outline-danger">
                <input type="checkbox" autocomplete="off" value="交通不方便">交通不方便
            </label>
        </div>

        <p>添加你自己的标签</p>
        <input name="myTags" id="myTags" class="form-control" placeholder="请使用分号隔开标签，每个标签不超8个字"/>

        <p>更多评价内容</p>
        <textarea name="content" id="content" class="form-control" rows="5" placeholder="请填写你对该旅游地的评价"></textarea>
    </div>
    <div class="container imgs ">
        <p>上传图片</p>

        <div class="row">
            <form id="imgForm" method="post" enctype="multipart/form-data" action="/tencentCloud/upload">
                <input id="pic" type="file" style="display: none" name="pic"/>
            </form>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
            <div class="col-3 rect">
                <span>上传</span>
            </div>
        </div>
    </div>

</div>


<div class="operation">
    <button class="btn" onclick="window.history.go(-1)">放弃评价</button>
    <button class="btn" id="submitBtn">提交评价</button>
</div>

</body>

<script>
    $(function () {
        var num = 1;
        //点星
        $(".starNum").click(function () {
            num = $(this).data("num");
            for (var i = 1; i <= num; i++) {
                $(".starNum[data-num=" + i + "]").css({"color": "yellow"});
            }
            for (var i = 5; i > num; i--) {
                $(".starNum[data-num=" + i + "]").css({"color": ""});
            }
        });

        //点击事件弹出文件上传框
        var rect = '';
        $(".rect").click(function () {
            rect = $(this);
            $("#pic").click();
        });
        //上传图片
        $("#pic").change(function () {
            if ($(this).val()) {
                $("#imgForm").ajaxSubmit(function (data) {
                    rect.html('<img src="' + data.url + '">');
                })
            }
        });


        //提交表单
        $("#submitBtn").click(function () {
            var imgUrls = '';
            $.each($(".rect"), function (index, ele) {
                if ($($(ele).html()).attr("src")) {
                    imgUrls += $($(ele).html()).attr("src") + ';';
                }
            });
            console.log(imgUrls);
            //获得所有的数据
            //标签
            var tags = $("#myTags").val();
            //内容
            var content = $("#content").val();

            $.ajax({
                type: "POST",
                url: "/strategyComments/addComment",
                data: {
                    starNum: num, imgUrls: imgUrls, content: content,
                    "strategy.id": getParams().strategyId, tags: tags
                },
                success: function (data) {
                    if (data.success) {
                        location.href = "/strategyCatalogs.html?strategyId=" + getParams().strategyId;
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '保存失败',
                            autoClose: 2000,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });
        });

    })
</script>

</html>